from neo4j import GraphDatabase

# 连接到 Neo4j 数据库
driver = GraphDatabase.driver('neo4j://49.235.155.102:7687', auth=('neo4j', '123qweasd!'))
session = driver.session()

print("=== 检查 Topic 节点 ===")
result = session.run('MATCH (t:Topic) RETURN t.name as topic_name, t.id as topic_id LIMIT 10')
topics = list(result)
print(f"找到 {len(topics)} 个 Topic 节点:")
for record in topics:
    print(f"  {record['topic_name']} (ID: {record['topic_id']})")

print("\n=== 检查 Subtopic 节点 ===")
result = session.run('MATCH (s:Subtopic) RETURN s.name as subtopic_name, s.id as subtopic_id LIMIT 10')
subtopics = list(result)
print(f"找到 {len(subtopics)} 个 Subtopic 节点:")
for record in subtopics:
    print(f"  {record['subtopic_name']} (ID: {record['subtopic_id']})")

print("\n=== 检查 Topic-Subtopic 关系 ===")
result = session.run('MATCH (s:Subtopic)-[r:PART_OF]->(t:Topic) RETURN t.name as topic, s.name as subtopic, type(r) as rel_type LIMIT 10')
relationships = list(result)
print(f"找到 {len(relationships)} 个 Topic-Subtopic 关系:")
for record in relationships:
    print(f"  {record['subtopic']} -> {record['topic']} ({record['rel_type']})")

print("\n=== 检查孤立的 Subtopic 节点 ===")
result = session.run('MATCH (s:Subtopic) WHERE NOT (s)-[:PART_OF]->() RETURN s.name as subtopic_name, s.id as subtopic_id LIMIT 10')
isolated_subtopics = list(result)
print(f"找到 {len(isolated_subtopics)} 个孤立的 Subtopic 节点:")
for record in isolated_subtopics:
    print(f"  {record['subtopic_name']} (ID: {record['subtopic_id']})")

print("\n=== 检查所有关系类型 ===")
result = session.run('MATCH ()-[r]->() RETURN DISTINCT type(r) as rel_type')
rel_types = list(result)
print("数据库中的关系类型:")
for record in rel_types:
    print(f"  {record['rel_type']}")

session.close()
driver.close()
print("\n检查完成！")